/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlayerRecord.java
 *
 * Created on 27/Dez/2011, 22:57:20
 */

package intopo.evogame.partnerselection.tools.analyser;

import java.io.DataInput;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 27/Dez/2011
 */
/**
 * Represents a record in the {@code Player} table.  Data to this table is written in methods {@code AbstractPlayer#writePlayer(int, int)} and {@code AbstractPlayer#writePlayer(int, int, int)}.  The output stream associated with the file is {@code Database#player}.  See the documentation of this field for the format of a record.
 * <p> This class provides methods to access a record of this table by its primary key.  This key is the player's identification.  The constructor of class {@code Player} writes a new record.  Therefore a single seek is suficient to obtain a record given the primary key.
 *
 * <p> Field {@code Record.ID} represents player's identification.  Corresponds to field {@code AbstractPlayer#ID}.  Primary key of the table.
 *
 * @see intopo.evogame.partnerselection.player.AbstractPlayer#ID
 *
 * @author pedro
 * @see intopo.evogame.partnerselection.player.AbstractPlayer#writePlayer(int, int)
 * @see intopo.evogame.partnerselection.player.AbstractPlayer#writePlayer(int, int, int)
 * @see intopo.evogame.partnerselection.Database#player
 */
class PlayerRecord
	  extends Record
{
	/**
	 * Reference to the chromosome of this player.
	 */
	int refIDChromosome;
	int refIDNode;
	int refIDParent;
	int bornTime;
	int deathTime;
	PlayerRecord ()
	{
		super (24);
	}
	void read (RandomAccessFile raf, int id)
		throws IOException
	{
		super.position (raf, id);
		this.readRest (raf);
	}
	void read (DataInput di)
		throws IOException
	{
		this.ID = di.readInt ();
		readRest (di);
	}
	private void readRest (DataInput di)
		throws IOException
	{
		this.refIDChromosome = di.readInt ();
		this.refIDNode = di.readInt ();
		this.refIDParent = di.readInt ();
		this.bornTime = di.readInt ();
		this.deathTime = di.readInt ();
	}
	@Override
	public int hashCode ()
	{
		return this.ID;
	}
	@Override
	public boolean equals (Object other)
	{
		return this.ID == ((PlayerRecord) other).ID;
	}
	public String toString ()
	{
		return String.format ("ID %d  c %d  n %d  p %d  bt %d  dt %d",
			this.ID,
			this.refIDChromosome,
			this.refIDNode,
			this.refIDParent,
			this.bornTime,
			this.deathTime);
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
